package top.sdaily.web.controller.sys;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.sdaily.web.context.ReturnBody;
import top.sdaily.web.model.Menu;
import top.sdaily.web.service.MenuService;

/**
 * Created by soya on 2017/1/19.
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    MenuService menuService;

    @GetMapping
    public ReturnBody getMenus(){
        return ReturnBody.success().setData(menuService.findAll());
    }

    @PostMapping
    public ReturnBody create(@RequestBody Menu menu){
        menuService.create(menu);
        return ReturnBody.success().setData(menu);
    }

    @PutMapping
    public ReturnBody modify(@RequestBody Menu menu){
        menuService.modify(menu);
        return ReturnBody.success().setData(menu);
    }

    @DeleteMapping("/{pkid}")
    public ReturnBody del(@PathVariable String pkid){
        menuService.delete(pkid);
        return ReturnBody.success();
    }
}
